package com.expense.app.admin.controller;

import com.expense.app.admin.annotation.IgnoreAuth;
import com.expense.app.admin.model.params.job.JobImportParam;
import com.expense.app.admin.model.params.job.mengniu.JobListParam;
import com.expense.app.admin.model.params.job.mengniu.JobParam;
import com.expense.app.admin.services.job.MengniuJobServ;
import com.expense.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;

/*
* 蒙牛 校招 管理 接口
* gen controller 2019-08-20
*/
@Validated
@RestController
@RequestMapping("/mengniu/job")
public class MengniuJobCtrl {

    @Autowired
    MengniuJobServ mengniuJobServ;

    @PostMapping("/import")
    public Result importExcel(@RequestBody JobImportParam param) {
        return Result.success(mengniuJobServ.importExcel(param));
    }

    @GetMapping("/list")
    public Result findList(@Validated JobListParam param) {
        return Result.success(mengniuJobServ.findList(param));
    }

    @IgnoreAuth
    @GetMapping("/web/list")
    public Result findWebList(@Validated JobListParam param) {
        return Result.success(mengniuJobServ.findList(param));
    }

    @IgnoreAuth
    @GetMapping("/web/list/{id}")
    public Result findJobDetail(@PathVariable @Min(1) Long id) {
        return Result.success(mengniuJobServ.findDetail(id));
    }

    @IgnoreAuth
    @GetMapping("/web/init")
    public Result findInitList(String project) {
        return Result.success(mengniuJobServ.findInitList(project));
    }

    @GetMapping(value = "/{id}")
    public Result findDetail (@PathVariable @Min(1) Long id) {
        return Result.success(mengniuJobServ.findDetail(id));
    }

    @PostMapping(value = "")
    public Result saveOne(@Validated @RequestBody JobParam param) {
        return Result.success(mengniuJobServ.saveOne(param));
    }

    @PutMapping(value = "")
    public Result update(@Validated @RequestBody JobParam param) {
        return Result.success(mengniuJobServ.saveOne(param));
    }

    @DeleteMapping(value = "/{id}")
    public Result deleteOne(@PathVariable @Min(1) Long id) {
        return Result.success(mengniuJobServ.deleteOne(id));
    }
}
